/*
 * SAMPLE - ESCAPE
 * Created by Greg Johnson
 * Converts HTML/CFML/JS reserved characters to HTML entities
 * optionaly escapeing the # signs in the entities for use inside CFOUTPUT areas
 * optionaly removes whitespace (tabs/spaces) before and after each line
 *
 * svn checkout http://sample-escape.googlecode.com/svn/trunk/ sample-escape
 */
function convertCodeForDisplay(text,dp,rw) {
	// Reserved Characters in HTML
	if (rw == 1) {
		text = text.replace(/^[\t\s]+|[\t\s]+$/mg,"");
	}
	text = text.replace(/"/g,'&#34;');
	text = text.replace(/''/g,'&#39;');
	text = text.replace(/&/g,'&amp;');
	text = text.replace(/</g,'&lt;');
	text = text.replace(/>/g,'&gt;');

	// Reserved Characters in ColdFusion
	text = text.replace(/#/g,'&#35;');

	// Reserved Characters in Javascript
	text = text.replace(/\\/g,'&#92;');
	if ( dp == 1) {
		text = text.replace(/#/g,'##');
	}
	return text;
}